package com.eleadmin.common.system.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.common.core.web.ApiResult;
import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.core.web.BatchParam;
import com.eleadmin.common.core.web.PageResult;
import com.eleadmin.common.system.entity.TaskType;
import com.eleadmin.common.system.param.TaskTypeParam;
import com.eleadmin.common.system.service.TaskTypeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 任务类型表控制器
 *
 * @author EleAdmin
 * @since 2025-04-22 22:55:28
 */
@Api(tags = "任务类型表管理")
@RestController
@RequestMapping("/system/taskType")
public class TaskTypeController extends BaseController {
    @Resource
    private TaskTypeService taskTypeService;


    @OperationLog
    @ApiOperation("分页查询任务类型表")
    @GetMapping("/page")
    public ApiResult<PageResult<TaskType>> page(TaskTypeParam param) {

        return success(taskTypeService.pageRel(param));

    }


    @OperationLog
    @ApiOperation("查询全部任务类型表")
    @GetMapping()
    public ApiResult<List<TaskType>> list() {


        return success(taskTypeService.list());

    }


    @OperationLog
    @ApiOperation("根据id查询任务类型表")
    @GetMapping("/{id}")
    public ApiResult<TaskType> get(@PathVariable("id") Integer id) {
        return success(taskTypeService.getById(id));

    }


    @OperationLog
    @ApiOperation("添加任务类型表")
    @PostMapping()
    public ApiResult<?> save(@RequestBody TaskType taskType) {
        if (taskTypeService.save(taskType)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @OperationLog
    @ApiOperation("修改任务类型表")
    @PutMapping()
    public ApiResult<?> update(@RequestBody TaskType taskType) {
        if (taskTypeService.updateById(taskType)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }


    @OperationLog
    @ApiOperation("删除任务类型表")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (taskTypeService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }


    @OperationLog
    @ApiOperation("批量添加任务类型表")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<TaskType> list) {
        if (taskTypeService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @OperationLog
    @ApiOperation("批量修改任务类型表")
    @PutMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody BatchParam<TaskType> batchParam) {
        if (batchParam.update(taskTypeService, "id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }


    @OperationLog
    @ApiOperation("批量删除任务类型表")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (taskTypeService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
